// pages/set/set.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isSetPayPassword: null, //是否设置了支付密码
    isBindingMobile: null,  //是否绑定了手机号
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({title: '加载中...',});
    wx.request({
      url: app.baseURL + 'Mine&a=set_pay',
      data: {
        type: 2, //
        user_id: app.globalData.userId
      },
      success: (res) => {
        //未设置支付密码
        this.setData({
          isSetPayPassword: res.data.info.pay_pwd,
          isBindingMobile: res.data.info.mobile
        });
        wx.hideLoading();
      },
      fail: (err) => {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        })
      }
    })
  },
  
  // 跳转设置支付密码
  toPassSet(e){
    const status = e.currentTarget.dataset.status;
    if (this.data.isBindingMobile == 0){
      wx.showModal({
        title: '提示',
        content: '你还未绑定手机号码，请先绑定手机号码再来设置',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/bindingMobile/bindingMobile',
            })
          }
        }
      })
    }
    if (this.data.isBindingMobile == 1){
      if (status == 0){
        wx.navigateTo({
          url: '/pages/passRecoverySet/passRecoverySet',
        })
      } else if (status == 1){
        wx.navigateTo({
          url: '/pages/passRecovery/passRecovery',
        })
      }
    }
  },
// /pages / passRecoverySet / passRecoverySet
  //Sign out
  signOut() {
    wx.showModal({
      title: '温馨提示',
      content: '是否退出登录？',
      confirmColor: '#f00',
      success: (res) => {
        if (res.confirm) {
          wx.clearStorage();
          try {
            wx.clearStorageSync()
          } catch (e) {
            throw new Error('调用wx.clearStorageSync()接口失败')
          }
          app.globalData.userId = null;
          wx.switchTab({
            url: '../index/index',
          })
        }
      }
    })
    
  }
})